package com.flaremars.picker.utils;

import android.content.Context;
import android.content.SharedPreferences;

import com.flaremars.picker.constants.PreferencesConstants;


/**
 * Created by FlareMars on 2016/3/1.
 */
public enum PreferencesUtils {
    INSTANCE;

    public String getString(Context context,String key) {
        SharedPreferences sharedPreferences = getSharedPreferences(context);
        return sharedPreferences.getString(key,"");
    }

    public boolean getBoolean(Context context,String key) {
        SharedPreferences sharedPreferences = getSharedPreferences(context);
        return sharedPreferences.getBoolean(key, true);
    }

    public int getInteger(Context context,String key) {
        SharedPreferences sharedPreferences = getSharedPreferences(context);
        String temp = sharedPreferences.getString(key, "");
        return temp.equals("") ? 400 : Integer.valueOf(temp);
    }

    public void putBoolean(Context context,String key,boolean value) {
        SharedPreferences sharedPreferences = getSharedPreferences(context);
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.putBoolean(key,value);
        editor.apply();
    }

    public void putInteger(Context context,String key,int value) {
        SharedPreferences sharedPreferences = getSharedPreferences(context);
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.putInt(key,value);
        editor.apply();
    }

    public void putString(Context context,String key,String value) {
        SharedPreferences sharedPreferences = getSharedPreferences(context);
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.putString(key,value);
        editor.apply();
    }

    private SharedPreferences getSharedPreferences(Context context) {
        return context.getSharedPreferences(PreferencesConstants.PRIMARY_NAME,Context.MODE_PRIVATE);
    }

}
